package com.lxyk.springcloud.service.impl;

import com.lxyk.springcloud.service.MessageProvider;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

//业务不是crud 而是绑定器进行信息交互
//这里我们做消息推送 我们并不是去调dao，所以不要写Service注解
@EnableBinding(Source.class)//source第一次写自动导的包是import javax.xml.transform.Source;不对，要删了包用快捷键导一下正确的包 Source.class代表消息推送方
public class MessageProviderImpl implements MessageProvider {
    @Resource//装配注解
    private MessageChannel output;//消息发送管道

    @Override
    public String send() {
        String str = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(str).build());//MessageBuilder也容易导错包
        System.out.println("str:"+str);
        return null;
    }
}
